home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / LITTLEST / !LittleST / st / TEST < prev    next >
Text File  |  1992-03-04  |  3KB  |  106 lines

  1. *
  2. *
  3. * Little Smalltalk, version 2
  4. * Written by Tim Budd, Oregon State University, July 1987
  5. * Modified to operate in RiscOS 3.0 by Geoff. Lane. Mar 1992
  6. *
  7. *  a few test cases.
  8. *
  9. * to use, first file in this file, then pas all to an instance of
  10. *    class Test, for example using the messages
  11. *
  12. *    File new; fileIn: 'st.test'
  13. *     Test new all
  14. *
  15. Class Test Object
  16. Class One Object
  17. Class Two One
  18. Class Three Two
  19. Class Four Three
  20. Methods One 'all'
  21.         test
  22.                 ^ 1
  23. |
  24.     result1
  25.                 ^ self test
  26. ]
  27. Methods Two 'all'
  28.         test
  29.                 ^ 2
  30. ]
  31. Methods Three 'all'
  32.         result2
  33.                 ^ self result1
  34. |
  35.     result3
  36.                 ^ super test
  37. ]
  38. Methods Four 'all'
  39.         test
  40.                 ^ 4
  41. ]
  42. Methods Test 'all'
  43.     all
  44.         self super.
  45.         self conversions.
  46.         self collections.
  47.         self factorial.
  48.         self filein.
  49.         'all tests completed' print
  50. |
  51.     conversions
  52.         " test a few conversion routines "
  53.         ( (#abc == #abc asString asSymbol) and: [
  54.         ($A == $A asInteger asCharacter) and: [
  55.         (12 == 12 asDigit digitValue) and: [
  56.         (237 == 237 asString asInteger) and: [
  57.         (43 = 43 asFloat truncated) and: [
  58.         $A == ($A asString at: 1) ] ] ] ] ] )
  59.             ifFalse: [^ smalltalk error: 'conversion failure'].
  60.         'conversion test passed' print.
  61. |
  62.     collections
  63.         " test the collection classes a little"
  64.         ( (#(1 2 3 3 2 4 2) asSet = #(1 2 3 4) asSet) and: [
  65.         (#(1 5 3 2 4) sort asArray = #(1 2 3 4 5)) and: [
  66.         (1 "(#+ respondsTo occurrencesOf: Float)" = 1) and: [
  67.         ('First' < 'last') ] ] ] )
  68.             ifFalse: [^smalltalk error: 'collection failure'].
  69.         'collection test passed' print.
  70. |
  71.     factorial    | t |
  72.         t <- [:x | (x = 1) ifTrue: [ 1 ] 
  73.                 ifFalse: [ x * (t value: x - 1) ] ].
  74.         ((t value: 5) = 5 factorial)
  75.             ifFalse: [ smalltalk error: 'factorial failure'].
  76.         'factorial test passed' print
  77. |
  78.     filein
  79.         File new; name: 'st.queen'; open: 'r'; fileIn.
  80.         "(globalNames includesKey: #Queen )
  81.             ifFalse: [ smalltalk error: 'fileIn failure']."
  82.         'file in test passed' print.
  83.         self queen
  84. |
  85.     super2         | x1 x2 x3 x4 |
  86.                 x1 <- One new.
  87.                 x2 <- Two new.
  88.                 x3 <- Three new.
  89.                 x4 <- Four new.
  90.         ^ List new; addLast: x1 test;
  91.             addLast: x1 result1;
  92.             addLast: x2 test;
  93.             addLast: x2 result1;
  94.             addLast: x3 test;
  95.                     addLast: x4 result1;
  96.                     addLast: x3 result2;
  97.             addLast: x4 result2;
  98.                     addLast: x3 result3;
  99.                     addLast: x4 result3
  100. |
  101.     super
  102.         (self super2 asArray = #(1 1 2 2 2 4 2 4 2 2) )
  103.             ifTrue: ['super test passed' print]
  104.             ifFalse: [ smalltalk error: 'super test failed']
  105. ]
  106.